package com.linlang.grasharepro.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.linlang.grasharepro.R;
import com.linlang.grasharepro.model.User;

import java.util.List;

/**
 * 商家WIFI适配器
 * Created by pengtao on 2016/6/3.
 */
public class MyFollowAdapter extends BaseAdapter {

    /**
     * 商家信息列表
     */
    private List<User> list;

    public List<User> getList() {
        return list;
    }

    public void setList(List<User> list) {
        this.list = list;
    }

    public Context getCtx() {
        return ctx;
    }

    public void setCtx(Context ctx) {
        this.ctx = ctx;
    }


    private Context ctx;


    public MyFollowAdapter(List<User> list, Context ctx) {
        this.list = list;
        this.ctx = ctx;
        // 实例化获取图片的类

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final Holder hold;
        if (convertView == null) {
            hold = new Holder();
            convertView = View.inflate(ctx, R.layout.item_follow, null);
            hold.tv_userName = (TextView) convertView.findViewById(R.id.tv_userName);//用户名
            hold.tv_introduction = (TextView) convertView.findViewById(R.id.tv_introduction);//简介
            convertView.setTag(hold);
        } else {
            hold = (Holder) convertView.getTag();
        }

        if (list != null && list.size() > 0) {
            final User user = list.get(position);
            hold.tv_userName.setText(user.getLoginName());
            hold.tv_introduction.setText(user.getIntroduction());

//            //点击删除按钮删除自己收藏的内容
//            hold.iv_delete.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    //获取用户登陆信息
//                    SharedPreferences preferences = ctx.getSharedPreferences("userInfo",
//                            Activity.MODE_PRIVATE);
//                    String account = preferences.getString("account", "");
//                    collectionDB = new CollectionDB(ctx);
//                    collectionDB.open();
//                    collectionDB.deleteByRelationId(smd.get_id(), account);
//                }
//            });
        }
        return convertView;
    }

    static class Holder {
        TextView tv_userName, tv_introduction;
    }
}
